 
const qiniu = require('qiniu')
// 创建上传凭证
const accessKey = 'x4hD-SRFSnrhXgV3O9PnlVuCE6A5lhU2wUTybPGJ'    //七牛的accessKey
const secretKey = 'LM2kGPle1vY-TTUYxgjwQU7eqSM38n-hY_y2GDM9'    //七牛的secretKey
const mac = new qiniu.auth.digest.Mac(accessKey, secretKey)
const bucket = '07n-cs'
const options = {
    scope: bucket,
    returnBody: `{"key":"$(key)","size":$(fsize),"name":"$(fname)","type":"$(mimeType)"}`
}
const putPolicy = new qiniu.rs.PutPolicy(options)
const uploadToken = putPolicy.uploadToken(mac)
const keyInQiniuCloud = 'image/' //七牛云文件目录
//服务器直传
const config = new qiniu.conf.Config();
// 空间对应的区域，若不配置将自动查询
config.regionsProvider = qiniu.httpc.Region.fromRegionId('z0');
// 是否使用https域名
//config.useHttpsDomain = true;
// 上传是否使用cdn加速
//config.useCdnDomain = true;
 
//图片的地址
var bucketManager = new qiniu.rs.BucketManager(mac, config);
var privateBucketDomain = 'http://sjh1x9l28.hd-bkt.clouddn.com'; //七牛中自己配置的域名地址
var deadline = parseInt(Date.now() / 1000) + 3600000; // 永不过期
 
const getFileUrl=(key)=> {
    // return bucketManager.privateDownloadUrl(privateBucketDomain, key); //公开空间
    return bucketManager.privateDownloadUrl(privateBucketDomain, key, deadline); //私有空间
}
module.exports = {
    mac,
    uploadToken,
    config,
    getFileUrl,
    keyInQiniuCloud,
    privateBucketDomain,
    jwtSecretKey: bucket
}